﻿''' <summary>
''' The UI end of the Assignments
''' </summary>
''' <remarks></remarks>
Public Class CollegiateAssignment
    Private Green As Brush = New SolidColorBrush(Color.FromRgb(102, 204, 102))
    Private Yellow As Brush = New SolidColorBrush(Color.FromRgb(255, 255, 51))
    Private Red As Brush = New SolidColorBrush(Color.FromRgb(204, 0, 0))
    Public Event editAssignment(ByVal e As String)
    Public Event deleteAssignment(ByVal e As String)
    Public Event changeCompleted(ByVal e As String, ByVal value As Boolean)

    ''' <summary>
    ''' Overloaded constructor which takes arguments
    ''' </summary>
    ''' <param name="name">The Assignment's name</param>
    ''' <param name="notes">The Assignment's notes</param>
    ''' <param name="course">Which course the Assignment belongs to</param>
    ''' <param name="courseColor">The color chosen to depict the Assignment's course</param>
    ''' <param name="dueDate">The date the Assignment is due</param>
    ''' <param name="priority">The priority level of the Assignment</param>
    ''' <param name="completed">Boolean value depicting whether the assignment is completed or not</param>
    ''' <remarks></remarks>
    Public Sub New(ByVal name As String, _
                   ByVal notes As String, _
                   ByVal course As String, _
                   ByVal courseColor As Color, _
                   ByVal dueDate As Date, _
                   ByVal priority As Integer, _
                   ByVal completed As Boolean)
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.AssignmentName = name
        Me.AssignmentNotes = notes
        Me.CourseName = course
        Me.CourseColor = courseColor
        Me.DueDate = dueDate
        Me.priority = priority
        Me.completed = completed
    End Sub

    ''' <summary>
    ''' Constructor that sets default values
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Me.AssignmentName = "Assignment Name"
        Me.AssignmentNotes = "Assignment Notes"
        Me.CourseName = "Course"
        Me.CourseColor = Color.FromRgb(102, 204, 102)
        Me.DueDate = Today.AddDays(1)
        Me.priority = 0
        Me.completed = True
    End Sub

    ''' <summary>
    ''' Writeonly property that modifies the Assignment Name
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property AssignmentName As String
        Set(ByVal value As String)
            Title.Content = value
        End Set
    End Property

    ''' <summary>
    ''' Writeonly property that modifies the Assignment Notes
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property AssignmentNotes As String
        Set(ByVal value As String)
            Notes.Content = value
        End Set
    End Property

    ''' <summary>
    ''' Writeonly property that modifies the name of the course the Assignment belongs to
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property CourseName As String
        Set(ByVal value As String)
            Course.Content = value
        End Set
    End Property

    ''' <summary>
    ''' Writeonly property that modifies the color shown on the UI element that depicts which course the Assignment belongs to
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property CourseColor As Color
        Set(ByVal value As Color)
            Course.Background = New SolidColorBrush(value)
        End Set
    End Property

    ''' <summary>
    ''' Writeonly property that modifies the date the Assignment is due
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property DueDate As Date
        Set(ByVal value As Date)
            Due.Content = value.Date
        End Set
    End Property

    ''' <summary>
    ''' Writeonly property that modifies the priority level (and hence color coding) of the Assignment
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property priority As Integer
        Set(ByVal value As Integer)
            Select Case value
                Case 0
                    PriorityIndicator.Background = Green
                Case 1
                    PriorityIndicator.Background = Yellow
                Case 2
                    PriorityIndicator.Background = Red
                Case Else
                    PriorityIndicator.Background = Green
            End Select
        End Set
    End Property

    ''' <summary>
    ''' Public Boolean property that keeps track of whether the assignment is completed or not
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property completed As Boolean
        Get
            Return IsCompleted.IsChecked
        End Get
        Set(ByVal value As Boolean)
            IsCompleted.IsChecked = value
        End Set
    End Property

    ''' <summary>
    ''' If the element is double-clicked, raise the "editAssignment" event
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub Grid_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
        If e.ClickCount = 2 Then
            ' if double click
            RaiseEvent editAssignment(Me.Name)
        End If
    End Sub

    ''' <summary>
    ''' If the element's "Edit Assignment" menuitem is selected, raise the "editAssignment" event
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub EditAssignment_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        RaiseEvent editAssignment(Me.Name)
    End Sub

    ''' <summary>
    ''' If the element's "Delete Assignment" menuitem is selected, raise the "deleteAssignment" event
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Private Sub DeleteAssignment_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        RaiseEvent deleteAssignment(Me.Name)
    End Sub

    ''' <summary>
    ''' If the checkbox depicting whether the assignment is completed or not is clicked, raise the "changeCompleted" event
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub completedClicked()
        RaiseEvent changeCompleted(Me.Name, completed)
    End Sub
End Class
